home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk64 / blk / blk.doc < prev    next >
Text File  |  1995-03-19  |  11KB  |  311 lines

  1.  
  2.  
  3.         blk - Automatic Requester Generator
  4.             Stuart Ferguson
  5.  
  6.  
  7. Blk generates C code for declaring requesters.  It automatically formats
  8. borders and text and generates the declarations for them.  The requester
  9. can contain boolean, string and proportional gadgets.
  10.  
  11.  
  12. Boxes:
  13.  
  14. A Requester and all its internal structures are described to blk as a
  15. tree of nested boxes.  The root box is the Requester itself.  Inner
  16. boxes can be stacked horizontally or vertically or be within each
  17. other.  Borders and text strings are also boxes for the purpose of
  18. formatting.  The box grammer, which is loosly based on lisp syntax, can
  19. be described by the BNF-like description given below.  (Non-terminal
  20. symbols are named and terminal symbols are double quoted strings.)
  21.  
  22.     box   :== fill | text | bord | block | seq
  23.     fill  :== "f"
  24.     text  :== "(t" onum str ")"
  25.     str   :== [double quoted string]
  26.     bord  :== rule | "(" rule num onum ")"
  27.     rule  :== "|" | "-"
  28.     block :== "(b" num num ")"
  29.     seq   :== "(" ("h"|"v") blist ")"
  30.     blist :== box | box blist
  31.     onum  :== num | [nothing]
  32.     num   :== [unsigned integer]
  33.  
  34.  
  35. Some examples:
  36.  
  37. The following box description would produce a 10 x 10 pixel area with
  38. borders on all four sides:
  39.  
  40.     (h | (v - (b 10 10) - ) | )
  41.  
  42. The central structure, "(b 10 10)," is a 10 x 10 block.  This is one of
  43. three boxes in a vbox, or vertically oriented list of boxes.  The other
  44. two boxes in the list are hrules, the "-"'s, which are horizontal "rules,"
  45. or lines.  This produces a box containing an empty area with lines above
  46. and below it.  This box is further included with two vertical rules, "|,"
  47. in an hbox - a horizontally oriented list.  This puts horizontal lines
  48. on each side of the box, closing the square.
  49.  
  50.       -----       |-----|
  51.       xxxxx       |xxxxx|
  52.       xxxxx       |xxxxx|
  53.       xxxxx       |xxxxx|
  54.       -----       |-----|
  55.  
  56. Rules are elastic, and while they have no intrinsic length of their own,
  57. they will expand to fill any space available within their bounding box.
  58. The vbox above:
  59.  
  60.     (v - (b 10 10) - )
  61.  
  62. has dimensions 10 x 12, so each horizontal rule expands to a length of
  63. 10 to fill the enclosing box.
  64.  
  65. Fills are another type of elastic object.  For example, suppose you wanted
  66. to format a set of strings, like:
  67.  
  68.     Line #1
  69.     Blah Blah
  70.     ETC
  71.  
  72. You could list the text boxes in a vbox, thus:
  73.  
  74.     (v (t "Line #1") (t "Blah Blah") (t "ETC"))
  75.  
  76. This would produce the formated lines as above.  But then suppose you wanted
  77. each line centered within its box.  For this you use fills.  Each fill
  78. expands to take up as much free space as it can within its bounding box,
  79. and if a string is sandwiched between two fills horizontally, it will be
  80. squeezed by competing fills into the center of its bounding box.
  81.  
  82.     (v
  83.        (h f (t "Line #1")   f)
  84.        (h f (t "Blah Blah") f)
  85.        (h f (t "ETC")       f)
  86.     )
  87.  
  88. Now the boxes within the outer vbox are not text boxes but hboxes
  89. containing text boxes and fills to the left and right.  The width of the
  90. vbox is computed as the maximum width of each box it contains.  Since
  91. fills have no intrinsic size, the widest hbox is the one containing the
  92. text box (t"Blah Blah"), which has a width of 9 characters (blk always 
  93. assumes a fixed size font).  If the characters are 8 pixels wide, the
  94. largest hbox will be 72 pixels.  Each of the other two shorter hboxes
  95. are contained within a vbox also of width 72, so each fill expands to
  96. make up the difference.  For example, the first hbox contains two fills
  97. and a 56 pixel wide text box.  To fill up a 72 pixel wide bounding box,
  98. each fill can expand 8 pixels horizontally, thus centering the text box
  99. inbetween them.  The result is:
  100.  
  101.      Line #1
  102.     Blah Blah
  103.        ETC
  104.  
  105. This whole structure is just a box, and can be used within other box
  106. structures.  For example, to put a border around the above box, you could
  107. use the definition from the first example.  Specifically:
  108.  
  109.  (h | (v - 
  110.    (v
  111.       (h f (t"Line #1")   f)
  112.       (h f (t"Blah Blah") f)
  113.       (h f (t"ETC")       f)
  114.     )
  115.   -) |)
  116.  
  117. The problem with this (you will see if you try it) is that the rules
  118. suround the text too closely.  Since there is no space between the text and
  119. the lines they lie almost right on top of each other.  Text boxes look fine
  120. right next to each other, but rules need to be explicitly spaced away from
  121. text.  This can be done with "struts," blocks used explicitly as spacers,
  122. like so:
  123.  
  124.     (h | (v - (b 0 5) (h (b 5 0)
  125.        (v
  126.           (h f (t"Line #1")   f)
  127.           (h f (t"Blah Blah") f)
  128.           (h f (t"ETC")       f)
  129.        )
  130.      (b 5 0)) (b 0 5) -) |)
  131.  
  132. The 0 x 5 and 5 x 0 blocks have no volume but since they have width or
  133. height, they affect the spacing of the other components in their h- or
  134. vboxes.
  135.  
  136. Text and rules take on the default color (see "blk files" below) unless the
  137. color is explicitly stated.  For text boxes this is done with the optional
  138. parameter in the text box description, as in (t 3 "hi there"), which
  139. specifies that the text be color #3.  For rules, a different description
  140. format is used.  Instead of simply | or -, a form such as (| 1 3) or (- 1 2)
  141. is used.  The two examples create a vrule of color 3 and an hrule of color 2
  142. respectively.  The first number is the width of the rule and should always
  143. be 1.
  144.  
  145. With these simple tools, it is possible to design a wide variety of nicely
  146. layed-out requesters without dealing with a single coordinate or C struct.  
  147. What is more, the strings in the above box definition could be changed to 
  148. anything, and the result would still be three strings centered within a 
  149. perfectly sized box.
  150.  
  151. Blk also supports a 'C'-style preprocesser for include files, macros,
  152. comments and "ifdef's".  Macros can make deeply nested box structures
  153. more readable and consistent.
  154.  
  155.  
  156. Gadgets:
  157.  
  158. Any sub-box in a box definition can be defined to be a gadget hit box by
  159. following it with the sequence:
  160.  
  161.    ":" num
  162.  
  163. From the above example, each text box could be defined as a hit box for a
  164. gadget by restating it as:
  165.  
  166.       (h f (t"Line #1"):1   f)
  167.       (h f (t"Blah Blah"):2 f)
  168.       (h f (t"ETC"):3       f)
  169.  
  170. Given these box definitions, blk will generate code for 3 BOOLEAN,
  171. RELVERIFY, REQGADGET, GADGHCOMP gadgets with the GadgetID's 1,2 and 3.
  172. Other types of gadgets can be defined using an extended gadget definition.
  173. These are of the form:
  174.  
  175.    num {"s"|"p"|"pv"|"ph"} {":"id} flags
  176.  
  177. Stuff in {}'s is optional; "id" and "flags" are double-quoted strings.
  178. "Num" is the id number for the gadget given after the ":" in the box
  179. definition.  The optional "s", "p", "pv" and "ph" specify string or 
  180. proportional gadgets, the default being boolean.  "ph" is a FREEHORIZ
  181. proportional gadget, "pv" is FREEVERT, and "p" is both.  The optional 
  182. "id" string specifies a string to be used for the GadgetID field in the
  183. gadget struct instead of just using "0x<num>," where num is the id 
  184. given in the box description.  "Flags" is a set of characters used to 
  185. specify flags available in defining a gadget.  Valid flags are (case 
  186. is significant):
  187.  
  188.       B : GADGHBOX
  189.       t : TOGGLESELECT
  190.       v : RELVERIFY
  191.       e : ENDGADGET
  192.       i : GADGIMMEDIATE
  193.       c : STRINGCENTER  (string gadgets only)
  194.       f : FOLLOWMOUSE
  195.  
  196. Some examples:
  197.  
  198. 1ph""             - horizontally moving proportional gadget with no flags
  199. 7:"OK_ID""ev"     - boolean gadget with id "OK_ID"
  200.                      RELVERIFY and ENDGADGET flags set
  201. 5s"v"             - RELVERIFY string gadget
  202. 5s:"STR_ID""i"    - string gadget with id "STR_ID", GADGIMMEDIATE flag
  203.  
  204.  
  205. Blk output:
  206.  
  207. The code that blk outputs follows some simple conventions.  These were
  208. implemented for my own convenience and can be changed by altering the source
  209. code.  Structs are assigned in arrays, the name of each array being some
  210. base name followed by the type of struct.  For example, if the base name
  211. were "xyz," some structs would be "xyz_req," "xyz_str," etc.  They are:
  212.  
  213.     struct Requester <base>_req      /* not an array */
  214.  
  215.     struct Gadget <base>_gad[]
  216.     struct IntuiText <base>_txt[]
  217.     struct Border <base>_brd[]
  218.     short <base>_brd_XY[]
  219.  
  220.     UBYTE <base>_nbuf[][NUMCHR]
  221.     struct StringInfo <base>_sinfo[]
  222.  
  223.     struct Image <base>_pimg[]
  224.     struct PropInfo <base>_pinfo[]
  225.  
  226. Some of these may be ommited if there are no data of that type.
  227.  
  228. In user code, the symbol "ta" must be declared as struct TextAttr as in:
  229.  
  230.     struct TextAttr ta = { ... };
  231. or
  232.     extern struct TextAttr ta;
  233.  
  234. To use string gadgets, the symbol "NUMCHR" must be #define'd as the number
  235. of characters in the string buffer.  The symbol "undo" must be declared as
  236.  
  237.     UBYTE undo[NUMCHR];
  238.  
  239. to be used as the undo buffer for string gadgets (or #define'd as NULL).  
  240. The string buffers will be assigned in the order that they are encountered
  241. in reading the box description, so the buffer for the first encountered 
  242. will be <base>_nbuf[0], the buffer for the second will be <base>_nbuf[1], 
  243. and so on.
  244.  
  245.  
  246. Blk files:
  247.  
  248. A blk input file contains all the information to describe a single
  249. requester.  It starts with a string that is to be the base name for this set
  250. of declarations.  There are then two optional numbers which are the default
  251. border color and default text color.  Neither need to be specified and will
  252. both default to 1.  Then comes the box definition followed by a set of
  253. extended gadget descriptions.  Some examples are included in this release.
  254.  
  255.  
  256. Using blk:
  257.  
  258. The blk commandline is:
  259.  
  260.     blk [-p|q|v|s|d|g] <infile> [<outfile>]
  261.  
  262.     <infile>    - Input description file -- required.
  263.     <outfile>    - Output 'C' header file.
  264.     -p        - Print box description.
  265.     -s        - Output 'C' header file to stdout.
  266.     -d        - Display a preview Requester.
  267.     -g        - Write global declarations.
  268.     -q        - Run quiet.
  269.     -v        - Run verbose.
  270.  
  271. "Infile" is the input requester description.  If no output is specified,
  272. the resulting Requester will be displayed in a window.  If output is
  273. specified, blk will not normally display a preview, but it will if the
  274. "-d" option is specified.  The "-p" option prints a description of the
  275. formatted box tree structure to stdout.  This can be a huge ammout of 
  276. output, but can be useful if you need to know the exact coordinates or 
  277. size of something.  "-g" will write the 'C' declrations as global; the
  278. default is "static".  'C' output can be redirected to stdout with the
  279. "-s" option.  If this option is used, "-q" is also assumed.
  280.  
  281. The preview Requester will work and can be played with.  Blk will display
  282. the classes of the messages it gets from Intuition as you play with the
  283. Gadgets in the Requester.  If the Requester itself has no "ENDGADGET"
  284. type gadgets for terminating the Requester, blk allows you to end the
  285. preview session by pressing ESC when the preview window is active.
  286.  
  287.  
  288. Caveats:
  289.  
  290. The program is massivly recursive.  Be sure that you have enough stack
  291. to deal with the box description you give.  The deeper you nest your
  292. box descriptions, the deeper blk will go in interpreting them.  I keep
  293. my stack at 12000 and don't have any problems with it.
  294.  
  295. Blk is intended in the same spirit as a compiler, so the 'C' output 
  296. declarations are not designed to be directly editable.  For example, 
  297. the Gadget flags are not described symbolically, but rather are dumped 
  298. numerically into the declared structures.  The answer to problems
  299. with this is to modify the blk source.
  300.  
  301. If you do decide to hack the source, be so kind as to keep me informed
  302. of any useful improvements you make in case I decide to do yet another
  303. version.
  304.  
  305.     Stuart Ferguson        1/89
  306.     (shf@well.UUCP)
  307.  
  308.     123 James Ave.
  309.     Redwood City, Ca.
  310.         94062
  311.